package it.antonio.ilpizze.func;
public class Either<LEFT, RIGHT> {
	
	private final LEFT left;
	private final RIGHT right;

	private Either(LEFT left, RIGHT right) {
		this.left = left;
		this.right = right;
	}

	public static <LEFT, RIGHT> Either<LEFT, RIGHT> left(LEFT left) {
		return new Either<LEFT, RIGHT>(left, null);
	}

	public static <LEFT, RIGHT> Either<LEFT, RIGHT> right(RIGHT right) {
		return new Either<LEFT, RIGHT>(null, right);
	}

	public LEFT left() {
		return left;
	}

	public RIGHT right() {
		return right;
	}

	public boolean isLeft() {
		return left != null;
	}
	public boolean isRight() {
		return right != null;
	}
	public boolean is(Class<?> clazz) {
		return (right != null && clazz.equals(right.getClass())) || (left != null && clazz.equals(left.getClass()));
	}
	
}